import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int i = 0;
        String[] cards = s.split("-");
        compare(cards[0],cards[1]);
    }
    public static void compare(String left,String right) {
           String[] lcards = left.split(" ");
           String[] rcards = right.split(" ");
        if (left.equals("joker JOKER") || right.equals("joker JOKER")) {
            System.out.println("joker JOKER");
            return ;
        }
        //长度相等情况，即空格数
        if (lcards.length == rcards.length) {
            if(left.equals("JOKER")||right.equals("JOKER")) {
                System.out.println("JOKER");
            }else if (left.equals("joker")||right.equals("joker")) {
                System.out.println("joker");
            }else {
                isCom(left,right);
            }
        }else {
            if(isBoom(left)){
                System.out.println(left);
            }else if(isBoom(right)){
                System.out.println(right);
            }else {
                System.out.println("ERROR");
            }
        }
    }
    public static boolean isBoom(String s) {
        if(s.length() == 7||s.length() == 11) {
            return true;
        }
        return false;
    }
    public static void isCom(String left,String right) {
        String poker = "345678910JQKA2";
        int l = 0, r = 0;
        for (int i = 0 ;i < poker.length(); i++) {
            if (left.charAt(0) == poker.charAt(i)) {
                l = i;
                break;
            }
        }
        for (int i = 0 ;i < poker.length(); i++) {
            if (right.charAt(0) == poker.charAt(i)) {
                r = i;
                break;
            }
        }
        if (l > r) {
            System.out.println(left);
            return ;
        }else {
            System.out.println(right);
            return ;
        }
    }
}
